<?php
class Habito extends Doctrine_Record {
    public function setTableDefinition() {
        $this->setTableName('habito');
        $this->hasColumn('nombre', 'string', 124);
        $this->hasColumn('id_contrato', 'integer');
    }
    
    public function setUp(){
        $this->hasMany('Contrato as contratos', array(
            'local' => 'id_habito_contrato',
            'foreign' => 'id_contrato_habito',
            'refClass' => 'HabitosContrato'
        ));
    }
    
    //INCIO DE GETERS Y SETERS
    public function getNombre() {
        return utf8_decode($this->_get('nombre'));
    }

    public function setNombre($nombre) {
        $this->_set('nombre', utf8_encode($nombre));
    }
    //FIN INCIO DE GETERS Y SETERS
    
    public static function toSelect () {
        $html = '<select id="selectHabito" name="habito">';
        $habitos = Doctrine::getTable('habito')->findAll();
        foreach ($habitos as $habito) {
            $html .= '<option value="'.$habito->id.'">'.$habito->nombre.'</option>';
        }
        $html .= '</select>';
        return $html;
    }
}
?>